<template>
  <div class="panel-1 card-common-cls" :class="{'mask-cls': maskable}" @click="click2Drag">
    <div class="panel-1-box" :style="{
        width: '100%',
        height: height + 'px',
        minHeight: '50px',
        textAlign: 'center',
        fontSize: fontSize + 'px',
      }">
        <p>
          panel - 1
          <br />
          高：{{height}}px
        </p>
    </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        width: 0,
      }
    },
    props: {
      item: Object,
      maskable: {
        type: Boolean,
        default: true,
      },
    },
    computed: {
      height() {
        let _originalH = this.item
          && this.item.height
          && !isNaN(parseInt(this.item.height))
          && parseInt(this.item.height)
          || 0;
        let _originalW = this.item
          && this.item.width
          && !isNaN(parseInt(this.item.width))
          && parseInt(this.item.width)
          || 0;
        let _newH = _originalH * this.width / _originalW;
        return parseInt(_newH);
      },
      fontSize() {
        // console.log(this.height);
        let _fontSize = 30;
        if (this.height <= 36) _fontSize = 12;
        else if (this.height <= 90) _fontSize = parseInt(this.height / 3);
        else _fontSize = 30;
        return _fontSize;
      },
    },
    mounted() {
      const _box = document.querySelector('.panel-1');
      this.width = _box.style.width || _box.clientWidth || _box.offsetWidth || _box.scrollWidth || 250;
    },
    methods: {
      click2Drag() {
        // console.log(e);
      },
    },
  }
</script>

<style lang="scss" scoped>
  .mask-cls::before {
    position: absolute;
    content: '';
    width: 100%;
    height: 100%;
    z-index: 999;
  }

  .card-common-cls {
    position: relative;
    width: 100%;
    max-width: 375px;
    z-index: 0;

    img {
      display: block;
      width: 100%;
      height: 100%;
      object-fit: contain;
    }
  }

  .panel-1-box {
    display: flex;
    align-items: center;
    justify-content: center;

    p {
      text-align: center;
      color: #f2f2f2;
      font-weight: 900;
    }
  }
</style>
